﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Jemer.Domain;
using Jemer.Data;
using Jemer.Data.Infrastructure;
using Jemer.Domain.Entities;
using Jemer.Data.Repositories;

namespace Jemer.Service
{
    
    public interface IProductAdvisoryInfoService
    {
        IQueryable<ProductAdvisoryInfo> GetProductAdvisoryInfos();
        ProductAdvisoryInfo GetProductAdvisoryInfo(int id);
        void CreateProductAdvisoryInfo(ProductAdvisoryInfo productAdvisoryInfo);
        void DeleteProductAdvisoryInfo(int id);
        void SaveProductAdvisoryInfo();
    }
    
    public class ProductAdvisoryInfoService : IProductAdvisoryInfoService
    {
        private readonly IProductAdvisoryInfoRepository productAdvisoryInfoRepository;
        private readonly IUnitOfWork unitOfWork;
        public ProductAdvisoryInfoService(IProductAdvisoryInfoRepository productAdvisoryInfoRepository, IUnitOfWork unitOfWork)
        {
            this.productAdvisoryInfoRepository = productAdvisoryInfoRepository;
            this.unitOfWork = unitOfWork;
        }  
        #region IProductAdvisoryInfoService Members

        public IQueryable<ProductAdvisoryInfo> GetProductAdvisoryInfos()
        {
            var productAdvisoryInfos = productAdvisoryInfoRepository.GetAll();
            return productAdvisoryInfos;
        }

        public ProductAdvisoryInfo GetProductAdvisoryInfo(int id)
        {
            var productAdvisoryInfo = productAdvisoryInfoRepository.GetById(id);
            return productAdvisoryInfo;
        }

        public void CreateProductAdvisoryInfo(ProductAdvisoryInfo productAdvisoryInfo)
        {
            productAdvisoryInfoRepository.Add(productAdvisoryInfo);
            SaveProductAdvisoryInfo();
        }

        public void DeleteProductAdvisoryInfo(int id)
        {
            var productAdvisoryInfo = productAdvisoryInfoRepository.GetById(id);
            productAdvisoryInfoRepository.Delete(productAdvisoryInfo);
            SaveProductAdvisoryInfo();
        }

        public void SaveProductAdvisoryInfo()
        {
            unitOfWork.Commit();
        }

        #endregion
    }
    
    
}